import scrapy
from tutorial.items import TutorialItem

class CsdnSpider(scrapy.Spider):
    name = "csdn"
    allowed_domains = ["csdn.net"]
    start_urls = [
        "https://blog.csdn.net/yee_0217/article/details/91447644",
        "https://blog.csdn.net/mangobar/article/details/85316838"
    ]

    def parse(self, response):
        for sel in response.xpath('//*[@id="asideProfile"]'):
            item = TutorialItem()
            item['author'] = sel.xpath('div[1]/div[2]/div[1]/a/span/text()').extract()
            item['fans'] = sel.xpath('div[2]/dl[2]/dt/span/text()').extract()
            item['like'] = sel.xpath('div[2]/dl[3]/dt/span/text()').extract()
            item['comment'] = sel.xpath('div[2]/dl[4]/dt/span/text()').extract()
            #print(author, fans, like, comment)
            yield item